<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="renderer" content="webkit">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>项目列表</title>
	<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div id="pageInTab" class="pageInTab">
		<div class="searchArea">
			<form id="searchBar">
				<div class="fieldset1 tabel_col clearFix">
					<div class="fieldBox col_33">
						<div class="label">供应商名称</div>
						<div class="field">
							<input name="splNm" id="splNm" type="text" onclick="chooseSpl()" class="ui-textbox" value=""> <span class="requiredSymbol">*</span>
							<input name="splId" id="splId" type="hidden">
						</div>
					</div>
					<div class="fieldBox col_33">
						<div class="label">合同号</div>
						<div class="field">
							<input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="">
						</div>
					</div>
					<div class="fieldBox col_33">
						<div class="label">所属事业部</div>
						<div class="field">
							<select name="buOrgCd" id="buOrgCd" data-value=" ">
								<c:forEach items="${searchBuOrgList}" var="kv">
									<c:if test="${kv.key == '00000001'}">
										<option value="${kv.key}" selected>${kv.value}</option>
									</c:if>
									<c:if test="${kv.key != '00000001'}">
										<option value="${kv.key}">${kv.value}</option>
									</c:if>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="fieldBox col_33">
						<div class="label">放款日期</div>
						<div class="field">
							<input ligerui="width: 120" name="payDateStart"
								   id="payDateStart" type="text" class="ui-datepicker" value=""
								   validate="{required:true}"> - <input
								ligerui="width: 120" name="payDateEnd" id="payDateEnd"
								type="text" class="ui-datepicker" value="" validate="{required:true}">
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="fieldBox col_33">
						<div class="label">支付表号</div>
						<div class="field">
							<input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="">
						</div>
					</div>
					<div class="fieldBox col_33">
						<div class="label">阶梯返利状态</div>
						<div class="field">
							<select name="applyState" id="applyState" data-value=" ">
								<option value="null" selected>--请选择--</option>
								<option value="0">未申请</option>
								<option value="2">返利中</option>
								<option value="3">已返利</option>
								<option value="4">审核不通过</option>
								<option value="5">不返利</option>
							</select>
						</div>
					</div>
					<div class="fieldBox col_33">
						<div class="label">是否大客户业务</div>
						<div class="field">
							<select name="isBigCstWork" id="isBigCstWork" data-value=" ">
								<option value="null" selected>--请选择--</option>
								<option value="0">否</option>
								<option value="1">是</option>
							</select>
						</div>
					</div>
                </div>
                <div class="btnsBox">
                    <span id="searchBtn" onclick="searchBtn()" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
                    <span id="addBtn" onclick="applyBtn();" class="sq-button sq-button-round">阶梯返利申请</span>
                    <span id="noRebBtn" onclick="showNoRebate();" class="sq-button sq-button-round">不返利标记</span>
                </div>
			</form>
		</div>
	</div>
	<div class="sqPanel_body">
        <div>
            总融资金额：<span id="totalFundAmt"></span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            已勾选融资金额:<span id="fundAmt"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            可返利：<span id="toFundAmt"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </div>
        <div id="ligergrid1" class="sq-grid"></div>
	</div>
	<div id="paySchmListDiv" class="sq-grid"></div>
	<div id="stepRebateApply" class="sq-grid" style="display: none">
		<div class="Wrapper">
			<div class="tabel_col clearFix">
				<div class="fieldBox col_80">
					<div class="label">阶梯返利金额合计（元）</div>
					<div class="field">
						<input name="stepRebateAmt" id="stepRebateAmt" type="text" class="ui-textbox" value="" readonly>
					</div>
				</div>
				<div class="fieldBox col_80">
					<div class="label">开户行帐号</div>
					<div class="field">
						<select name="accNo" id="accNo" onchange="chooseAccNo()" data-value=" ">
                            <option value="">--请选择--</option>
						</select>
                        <input type="hidden" id="accNoHid" value="">
					</div>
				</div>
				<div class="fieldBox col_80">
					<div class="label">账户名</div>
					<div class="field">
						<input name="rcptUnt" id="rcptUnt" type="text" class="ui-textbox" value="" readonly>
					</div>
				</div>
				<div class="fieldBox col_80">
					<div class="label">开户行及支行</div>
					<div class="field">
						<input name="bkNm" id="bkNm" type="text" class="ui-textbox" value="" readonly>
					</div>
				</div>
				<div class="fieldBox col_80">
					<div class="label">开户行行号</div>
					<div class="field">
						<input name="bkNo" id="bkNo" type="text" class="ui-textbox" value="" readonly>
					</div>
				</div>

				<div class="clearFix"></div>
				<div class="btnsBox">
					<span id="toApply" onclick="toApply();" class="sq-button sq-button-round">发起申请</span>
					<span id="cancle" onclick="cancle();" class="sq-button sq-button-round">取消</span>
				</div>
			</div>
		</div>
	</div>
	<div id="chooseSplDiv" style="display: none">
		<div class="Wrapper">
			<div class="searchArea">
				<div class="fieldBox col_10">
					<div class="label">经销商名称</div>
					<div class="field">
						<input name="conditionSplNm" id="conditionSplNm" type="text" class="ui-textbox" value="">
					</div>
				</div>

				<div class="btnsBox">
					<span id="searchSpl" onclick="chooseSpl();" class="sq-button sq-button-round">查询</span>
					<span id="cancleSpl" onclick="ensure();" class="sq-button sq-button-round">确定</span>
				</div>
				<div id="chooseSpl"></div>
			</div>
		</div>
	</div>

	<div id="noRebateDiv" style="display: none">
		<div class="fieldset1 clearFix">
			<div class="fieldBox" >
				<div class="label">供应商名称:</div>
				<div class="field">
					<span name="splNmNoRe" id="splNmNoRe" type="text"   class="ui-textbox" value=""/>
				</div>
			</div>
		</div>
		<div class="fieldset1 clearFix">
			<div class="fieldBox" >
				<div class="label">阶梯返利金额合计(元):</div>
				<div class="field">
					<span name="rebateAmt" id="rebateAmt" type="text"   class="ui-textbox" value=""/>
				</div>
			</div>
		</div>
		<div class="fieldset1 clearFix">
			<div class="fieldBox" >
				<div class="label">不返利原因</div>
				<div class="field">
					<textarea name="noRebateRst" id="noRebateRst" type="text"   class="layui-textarea" value="" style="width:90%"></textarea>
				</div>
			</div>
		</div>
		<div class="fieldset1 clearFix">
			<div class="btnsBox">
				<span id="saveNoRebate" class="sq-button sq-button-round" onclick="applyNoRebate()">保存</span>
				<span class="sq-button sq-button-round" onclick="cancle()">取消</span>
			</div>
		</div>
		</div>
		<div id="cancelNoRebateDiv" style="display: none">
			<div class="fieldBox" >
				<span>确认撤销不返利标记吗？<br/></span>
			</div>
			<div class="fieldset1 clearFix">
				<span id="cancelNoRebate" class="sq-button sq-button-round" onclick="cancelNoRebate()">确认</span>
				<span class="sq-button sq-button-round" onclick="cancle()">取消</span>
			</div>
		</div>
		<div id="chooseVech"></div>
	</div>
</div>
<script type="text/javascript">
    var isAllowRebate = false ;
    var splBankAccList = [] ;
	var feeDetailVOList = [] ;
	var applyBtn = function () {
		checkSchm(null);
        if(isAllowRebate){
            // 弹窗
            $.ligerDialog.open({ title:'阶梯返利申请',target: $("#stepRebateApply"), width: 300, height:400 });
        }else{
			$.ligerDialog.open({ title:'该支付表不可发起返利申请，请重新选择',target: $("#stepRebateApply"), width: 300, height:400 });
		}
	}
	var searchBtn = function(){
		if (!$("#splId").val()){
			top.$.ligerDialog.SQalert({content: "请选择供应商！", SQ_type: "warning"});
			return false ;
		} 
		if (!$("#payDateStart").val() || !$("#payDateEnd").val()) {
			top.$.ligerDialog.SQalert({content: "请选择放款时间！", SQ_type: "warning"});
			return false ;
		}
		if (new Date($("#payDateStart").val()).getTime() - new Date($("#payDateEnd").val()).getTime() > 0){
			top.$.ligerDialog.SQalert({content: "开始时间不能大于结束时间！", SQ_type: "warning"});
			return false ;
		}
		if(new Date($("#payDateEnd").val()).getTime() - new Date($("#payDateStart").val()).getTime() > 365*24*3600*1000){
			top.$.ligerDialog.SQalert({content: "请选择一年以内的时间间隔！", SQ_type: "warning"});
			return false ;
		}
		$("#fundAmt").text('￥0');
		$("#toFundAmt").text('￥0');
		$("#paySchmListDiv").ligerGrid({
			url: '<%=path%>/prjsteprebate/steprebateBscInfo/getPrjStepSchmList.do',
			method : 'post',
			dataType: 'json',
			contentType: 'application/json',
			parms : {
				splId:$("#splId").val(),
				lsCntNo:$("#lsCntNo").val(),
				paySchNo:$("#paySchNo").val(),
				buOrgCd:$("#buOrgCd").val(),
				applyState:$("#applyState").val() === 'null'?null:$("#applyState").val() ,
				isBigCstWork:$("#isBigCstWork").val()=='null'?null:$("#isBigCstWork").val(),
				payDateStart:$("#payDateStart").val()?new Date($("#payDateStart").val()):null,
				payDateEnd:$("#payDateEnd").val()?new Date($("#payDateEnd").val()+" 23:59:59"):null
			},
			columns: [
				{ display: '供应商名称', name: 'splNm', align:'left',minWidth: 140},
				{ display: '合同号', name: 'lsCntNo', minWidth: 140,align:'center'},
				{ display: '支付表号', name: 'paySchNo', minWidth: 160,align:'center'},
				{ display: '承租人姓名', name: 'cstNm', width: 100},
				{ display: '融资金额', name: 'actLsAmt',minWidth: 140,
					render:function (rowdata) {
						var h = '&yen; ' + SQ.utils.currencyFormatter(rowdata.actLsAmt, 2) ;
						return h;
					}
				},
				{ display: '放款时间', name: 'actPayTm',minWidth: 140,
					render:function (rowdata,index,value) {
						return renderDate(rowdata,index,value);
					}
				},
				{ display: '资管机构', name: 'fundRasInsNm', width: 100},
				{ display: '是否大客户业务', name: 'isBigCstWork',minWidth: 60,
					render:function(rowdata){
						if(rowdata.isBigCstWork == 1){
							return "是";
						}else {
							return "否";
						}
					}
				},
				{ display: '申请单号', name: 'precessNo', width: 100,
					render: function (rowdata, rowindex, value) {
						var h = '';
						if (value && value != "null") {
							h += '<a href="javascript:showFlow(';
							h += "'" + rowdata.processId + "',";
							h += "'" + rowdata.audStsCd + "',";
							h += "'" + rowdata.id + "'";
							h += ')">' + value + '</a>'
						}
						return h;
					}
				},
				{ display: '阶梯返利状态', name: 'applyState', minWidth: 60,
					render:function(rowdata){
						if (!rowdata.applyState ||　rowdata.applyState==0){
							return "未申请";
						}
						if(rowdata.applyState == 2){
							return "返利中";
						}
						if(rowdata.applyState == 3){
							return "已返利";
						}
						if(rowdata.applyState == 4){
							return "审核不通过";
						}
						if(rowdata.applyState == 5){
							return "不返利";
						}
					}
				},
				{ display: '不返利原因', name: 'noRebateRst', align:'left',minWidth: 140,
					render:function(rowdata){
						if (rowdata.applyState==0) {
							return '' ;
						}
						return rowdata.noRebateRst ;
					}
				},
			],
			onBeforeCheckRow: function (checked, data, rowindex, rowobj){
				if (rowobj.applyState == 3){
					top.$.ligerDialog.SQalert({content: "该支付表返利申请已通过，不可再次申请！" + result.info, SQ_type: "warning"});
					return false;
				}
				$("#fundAmt").text('￥0');
				$("#toFundAmt").text('￥0');
				return checkSchm(data);
			},
			onCheckRow: function (checked, data, rowindex, rowobj){
				var fundAmt = 0 ;
				var checkedRows = $("#paySchmListDiv").ligerGrid().getCheckedRows();
				for(var i=0;i<checkedRows.length;i++){
					fundAmt += checkedRows[i].actLsAmt ;
				}
				$("#fundAmt").text('￥' + SQ.utils.currencyFormatter(fundAmt, 2));
				checkSchm();
			},
			onUnSelectRow: function (checked, data, rowindex, rowobj){
				if(!checked){
					return true ;
				}
				var fundAmt = 0 ;
				var checkedRows = $("#paySchmListDiv").ligerGrid().getCheckedRows();
				for(var i=0;i<checkedRows.length;i++){
					fundAmt += checkedRows[i].actLsAmt ;
				}
				$("#fundAmt").text('￥' + SQ.utils.currencyFormatter(fundAmt, 2));
				checkSchm();
			},
			onBeforeCheckAllRow:function(checked,element){
			    if(!checked){
			    	return true ;
				}
				var fundAmt = 0 ;
				var checkedRows = $("#paySchmListDiv").ligerGrid().getData();
				for(var i=0;i<checkedRows.length;i++){
					fundAmt += checkedRows[i].actLsAmt ;
				}
				$("#fundAmt").text('￥' + SQ.utils.currencyFormatter(fundAmt, 2));
				for (var i=0;i<checkedRows.length;i++){
					if(!checkSchm(checkedRows[i])){
						return false ;
					}
				}
			},
			onCheckAllRow: function(checked,element){
				if (!checked){
					return true ;
				}
				var fundAmt = 0 ;
				var checkedRows = $("#paySchmListDiv").ligerGrid().getCheckedRows();
				for(var i=0;i<checkedRows.length;i++){
					fundAmt += checkedRows[i].actLsAmt ;
				}
				$("#fundAmt").text('￥' + SQ.utils.currencyFormatter(fundAmt, 2));
				checkSchm();
			},
			onSuccess : function(data,grid){
				if (data && data.totalLsAmt){
					$("#totalFundAmt").text('￥' + SQ.utils.currencyFormatter(data.totalLsAmt, 2));
				} else{
					$("#totalFundAmt").text('￥0');
				}
			},
			usePager:true,
			page:1,
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton : true,
			checkbox:true,
			width: '100%',
			height:'100%',
			rownumbers:true,
			selectRowButtonOnly:true
		});
		// 查询经销商收款账户列表
        searSplAccList($("#splId").val());
	}
	function checkSchm(row){
		$("#toFundAmt").text('￥0');
		var paySchs = '';
		var checkedRows = $("#paySchmListDiv").ligerGrid().getCheckedRows();
		if(row){
			checkedRows.push(row) ;
		}
		if (checkedRows.length == 0) {
			$("#toFundAmt").text('￥0');
		    return false ;
        }
		for(var i=0;i<checkedRows.length;i++){
			if (i==checkedRows.length -1){
				paySchs += checkedRows[i].paySchId+''
			}else{
				paySchs += checkedRows[i].paySchId+',';
			}
		}
		$.ajax({
			type: 'get',
			url: '<%=path%>/prjsteprebate/steprebateBscInfo/getStepRebateFee.do',
            dataType:'json',
			async:false,
			data:{
				splId:$("#splId").val(),
				paySchs:paySchs
			},
			success: function (result) {
			    if (result.success && result.data){
                    $("#toFundAmt").text('￥' + result.data.stepRebateAmt);
                    $("#stepRebateAmt").val(result.data.stepRebateAmt);
                    isAllowRebate = true ;
                } else{
					$("#toFundAmt").text('￥0');
                    top.$.ligerDialog.SQalert({content: result.info, SQ_type: "warning"});
					isAllowRebate = false ;
                    return false ;
                }
			},
			error:function () {
				$("#toFundAmt").text('￥0');
				top.$.ligerDialog.SQalert({content: "查询数据失败！", SQ_type: "warning"});
				return false ;
			}
		})
		if (!isAllowRebate){
			return false ;
		}else{
			return true ;
		}
	}
	function chooseSpl() {
		$("#chooseSplDiv").show();
		$.ligerDialog.open({ title:'阶梯返利申请',target: $("#chooseSplDiv"), width: 500, height:500 });
		var conditionSplNm = $("#conditionSplNm").val();
		$("#chooseSpl").ligerGrid({
			url: '<%=path%>/product/splInfo/initList.do',
			method : 'get',
			parms : {
				splNm:conditionSplNm,
				buOrgCd:'00000001'
			},
			columns: [
				{ display: '经销商名称', name: 'splNm', minWidth: 100},
				{ display: '所属机构', name:'buOrgCdNms', minWidth:100}
			],
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton : true,
			width: '100%',
			height:'100%',
			heightDiff:-2,
			//isScroll: false,
			checkbox:true,
			rownumbers:true
		})
	}
	function ensure() {
		var select = $("#chooseSpl").ligerGrid().getSelectedRows();
		if (select.length != 1){
			top.$.ligerDialog.SQalert({content: "请选择一条数据！", SQ_type: "warning"});
			$.ligerDialog.hide();
			return false ;
		}
		$("#splNm").val(select[0].splNm);
		$("#splId").val(select[0].id);
		$.ligerDialog.hide();
		$("#chooseSplDiv").hide();
	}
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	function searSplAccList(splId) {
		$.ajax({
			type: 'get',
			url: '<%=path%>/prjsteprebate/steprebateBscInfo/getSplBankInfoBySplId.do',
			dataType:'json',
			data:{
				splId:splId,
			},
			success: function (result) {
				if (result.success && result.data){
					splBankAccList = result.data ;
					var options = '<option value="">--请选择--</option>' ;
					for(var i=0;i<result.data.length;i++){
						options += '<option value="' + result.data[i].id + '">'+result.data[i].accNo+'</option>'
					}
					$("#accNo").html(options)
				} else{
					top.$.ligerDialog.SQalert({content: result.info, SQ_type: "warning"});
					return false ;
				}
			},
			error:function () {
				top.$.ligerDialog.SQalert({content: "查询数据失败！", SQ_type: "warning"});
				return false ;
			}
		})
	}
	function toApply(){
		var splId = $("#splId").val();
		var splNm = $("#splNm").val();
		var stepRebateAmt = $("#stepRebateAmt").val();
		var accNo = $("#accNoHid").val();
		var rcptUnt = $("#rcptUnt").val();
		var bkNm = $("#bkNm").val();
		var bkNo = $("#bkNo").val();

        var paySchs = '';
        var selectedRows = $("#paySchmListDiv").ligerGrid().getSelectedRows() ;
		var isBigCheck  ;
		for (var i=0;i<selectedRows.length;i++){
			isBigCheck = selectedRows[i].isBigCstWork ;
			if (i>0 && isBigCheck !== selectedRows[i-1].isBigCstWork){
				top.$.ligerDialog.SQalert({content: "大客户业务与非大客户业务返利政策不同，请分别发起流程！", SQ_type: "warning"});
				return false ;
			}
			if (selectedRows[i].applyState == 5){
				top.$.ligerDialog.SQalert({content: "存在不返利的支付表，不能发起返利流程", SQ_type: "warning"});
				return false ;
			}
			if (selectedRows[i].applyState == 1 || selectedRows[i].applyState == 2 || selectedRows[i].applyState == 3){
				top.$.ligerDialog.SQalert({content: "只有未申请或审核不通过状态的支付表才能发起返利流程", SQ_type: "warning"});
				return false ;
			}
			if (i == selectedRows.length - 1){
				paySchs += selectedRows[i].paySchId;
			} else{
				paySchs += selectedRows[i].paySchId + ',';
			}
		}
		if (!splId){
			top.$.ligerDialog.SQalert({content: "请选择经销商！", SQ_type: "warning"});
			return false ;
		}
		if (!selectedRows || selectedRows.length == 0){
            top.$.ligerDialog.SQalert({content: "请选择可返利的支付表！", SQ_type: "warning"});
            $.ligerDialog.hide();
            return false ;
		}
		if(selectedRows.length > 10){
            top.$.ligerDialog.SQalert({content: "最多可选10个支付表！", SQ_type: "warning"});
            $.ligerDialog.hide();
            return false ;
        }
		if (!accNo || !rcptUnt){
			top.$.ligerDialog.SQalert({content: "请选择供应商收款账户！", SQ_type: "warning"});
			$.ligerDialog.hide();
			return false ;
		}
		$.ajax({
			type: 'post',
			url: '<%=path%>/prjsteprebate/steprebateBscInfo/add.do',
			dataType:'json',
			data:{
				splId:splId,
				splNm:splNm,
				stepRebateAmt:stepRebateAmt,
				accNo:accNo,
				rcptUnt:rcptUnt,
				bkNm:bkNm,
				bkNo:bkNo,
                paySchIds:paySchs
			},
			success: function (result) {
				if (result.success && result.data){
					$.ligerDialog.hide();
					top.$.ligerDialog.SQalert({content: '已成功提交返利申请', SQ_type: "success"});
					$("#paySchmListDiv").ligerGrid().reload();
				} else{
					top.$.ligerDialog.SQalert({content: result.info, SQ_type: "warning"});
					$.ligerDialog.hide();
					return false ;
				}
			},
			error:function () {
				top.$.ligerDialog.SQalert({content: "提交返利申请失败！", SQ_type: "warning"});
				$.ligerDialog.hide();
				return false ;
			}
		})
		$.ligerDialog.hide();
    }
    function showNoRebate() {
		var splId = $("#splId").val();
		var stepRebateAmt = $("#stepRebateAmt").val();
		var selectedRows = $("#paySchmListDiv").ligerGrid().getSelectedRows() ;

		$("#splNmNoRe").text($("#splNm").val()) ;
		$("#rebateAmt").text($("#stepRebateAmt").val()) ;

		if (!splId){
			top.$.ligerDialog.SQalert({content: "请先选择经销商！", SQ_type: "warning"});
			return false ;
		}
		if (!selectedRows || selectedRows.length == 0){
			top.$.ligerDialog.SQalert({content: "请先选择支付表！", SQ_type: "warning"});
			return false ;
		}
		// 取消不返利flag
		var flag = false;
		for(var i=0;i<selectedRows.length ; i++){
			if (selectedRows[i].applyState == 5) {
				flag = true ;
				break ;
			}
		}
		// 如果flag==false,就是标记不返利操作
		if (!flag){
			for (var i=0;i<selectedRows.length ; i++){
				if (!selectedRows[i].applyState === undefined && selectedRows[i].applyState !== '0' && selectedRows[i].applyState !== '4') {
					top.$.ligerDialog.SQalert({content: "只有未申请或者申请不通过状态的支付表才能设置不返利标识！", SQ_type: "warning"});
					return false ;
				}
			}
			$("#noRebateDiv").show() ;
			$.ligerDialog.open({ title:'不返利标记',target: $("#noRebateDiv"), width: 500, height:500 });
		} else{ // 如果flag==true,就是取消不返利操作
			for (var i=0;i<selectedRows.length ; i++){
				if (selectedRows[i].applyState != 5) {
					top.$.ligerDialog.SQalert({content: "不能操作不返利状态和其他状态的支付表", SQ_type: "warning"});
					return false ;
				}
			}
			$("#cancelNoRebateDiv").show() ;
			$.ligerDialog.open({ title:'撤销不返利标记',target: $("#cancelNoRebateDiv"), width: 300, height:200 });
		}
	}
    function applyNoRebate(){
		var splId = $("#splId").val();
		var splNm = $("#splNm").val() ;
		var stepRebateAmt = $("#stepRebateAmt").val();
		var noRebateRst = $("#noRebateRst").val();
		var paySchs = '';
		var selectedRows = $("#paySchmListDiv").ligerGrid().getSelectedRows() ;
		var isBigCheck  ;
		for (var i=0;i<selectedRows.length;i++){
			isBigCheck = selectedRows[i].isBigCstWork ;
			if (i>0 && isBigCheck != selectedRows[i-1].isBigCstWork){
				top.$.ligerDialog.SQalert({content: "不能同时设置大客户和非大客户业务的不返利标记！", SQ_type: "warning"});
				return false ;
			}
			if (i == selectedRows.length - 1){
				paySchs += selectedRows[i].paySchId;
			} else{
				paySchs += selectedRows[i].paySchId + ',';
			}
		}
		if (!splId){
			top.$.ligerDialog.SQalert({content: "请选择经销商！", SQ_type: "warning"});
			return false ;
		}
		if (!selectedRows || selectedRows.length == 0){
			top.$.ligerDialog.SQalert({content: "请选择可返利的支付表！", SQ_type: "warning"});
			$.ligerDialog.hide();
			return false ;
		}
		if(selectedRows.length > 10){
			top.$.ligerDialog.SQalert({content: "最多可选10个支付表！", SQ_type: "warning"});
			$.ligerDialog.hide();
			return false ;
		}
		if (!noRebateRst) {
			top.$.ligerDialog.SQalert({content: "请填写不返利原因！", SQ_type: "warning"});
			return false ;
		}
		if(noRebateRst.length > 20){
            top.$.ligerDialog.SQalert({content: "不返利原因不能超过20个字符！", SQ_type: "warning"});
            return false ;
        }
		$.ajax({
			type: 'post',
			url: '<%=path%>/prjsteprebate/steprebateBscInfo/applyNoRebate.do',
			dataType:'json',
			data:{
				splId:splId,
				splNm:splNm,
				stepRebateAmt:stepRebateAmt,
				paySchIds:paySchs,
				noRebateRst:noRebateRst
			},
			success: function (result) {
				if (result.success && result.data){
					$.ligerDialog.hide();
					top.$.ligerDialog.SQalert({content: '标记成功', SQ_type: "success"});
					$("#paySchmListDiv").ligerGrid().reload();
				} else{
					top.$.ligerDialog.SQalert({content: result.info, SQ_type: "warning"});
					$.ligerDialog.hide();
					return false ;
				}
			},
			error:function () {
				top.$.ligerDialog.SQalert({content: "标记不返利失败！", SQ_type: "warning"});
				$.ligerDialog.hide();
				return false ;
			}
		})
		$.ligerDialog.hide();
	}
	function cancelNoRebate() {
		var paySchs = '';
		var selectedRows = $("#paySchmListDiv").ligerGrid().getSelectedRows() ;
		var isBigCheck  ;
		for (var i=0;i<selectedRows.length;i++){
			isBigCheck = selectedRows[i].isBigCstWork ;
			if (i>0 && isBigCheck != selectedRows[i-1].isBigCstWork ){
				top.$.ligerDialog.SQalert({content: "不能同时设置大客户和非大客户业务的不返利标记！", SQ_type: "warning"});
				return false ;
			}
			if (i == selectedRows.length - 1){
				paySchs += selectedRows[i].paySchId;
			} else{
				paySchs += selectedRows[i].paySchId + ',';
			}
		}
		if (!splId){
			top.$.ligerDialog.SQalert({content: "请选择经销商！", SQ_type: "warning"});
			return false ;
		}
		if (!selectedRows || selectedRows.length == 0){
			top.$.ligerDialog.SQalert({content: "请选择可返利的支付表！", SQ_type: "warning"});
			$.ligerDialog.hide();
			return false ;
		}
		if(selectedRows.length > 10){
			top.$.ligerDialog.SQalert({content: "最多可选10个支付表！", SQ_type: "warning"});
			$.ligerDialog.hide();
			return false ;
		}
		$.ajax({
			type: 'post',
			url: '<%=path%>/prjsteprebate/steprebateBscInfo/cancleNoRebate.do',
			dataType:'json',
			data:{
				paySchIds:paySchs,
			},
			success: function (result) {
				if (result.success){
					$.ligerDialog.hide();
					top.$.ligerDialog.SQalert({content: '撤销不返利成功', SQ_type: "success"});
					$("#paySchmListDiv").ligerGrid().reload();
				} else{
					top.$.ligerDialog.SQalert({content: result.info, SQ_type: "warning"});
					$.ligerDialog.hide();
					return false ;
				}
			},
			error:function () {
				top.$.ligerDialog.SQalert({content: "撤销不返利失败！", SQ_type: "warning"});
				$.ligerDialog.hide();
				return false ;
			}
		})
		$.ligerDialog.hide();
	}
	function showFlow(processId,_audStsCd,bizId) {
		if (StringUtils.isEmpty(bizId) || StringUtils.isEmpty(processId)) {
			UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
			return;
		}
		var _formUrl = "/prjsteprebate/steprebateBscInfo/toDetailPage.do?isDetail=1@@id=";
		var params = "?pInsId=" + processId + "&status=" + _audStsCd + "&businessKey=" + bizId + "&formUrl=" + _formUrl;
		Add_navTab('tab_step_rebate' + processId, '查看流程', "<%=path%>/flow/flow/toFlowShowPageFowBus.do" + params);
	}
    function chooseAccNo(){
		var accNoId = $("#accNo").val();
		$("#accNoHid").val('');
		for (var i=0;i<splBankAccList.length;i++){
			if (accNoId == splBankAccList[i].id){
				$("#accNo").val(splBankAccList[i].id);
				$("#accNoHid").val(splBankAccList[i].accNo);
				$("#rcptUnt").val(splBankAccList[i].rcptUnt);
				$("#bkNm").val(splBankAccList[i].bkNm);
				$("#bkNo").val(splBankAccList[i].bkNo);
				return ;
			}
		}
	}
	function cancle(){
		$.ligerDialog.hide();
	}
	function clearBtn(){
		form.setData({
			splId:"",
			splNm:"",
			lsCntNo:"",
			paySchNo:"",
			payDateStart:"",
			payDateEnd:"",
			isBigCstWork:"null",
			applyState:"null"
		});
	}
	var form = $("#searchBar").ligerForm();
</script>
</body>
</html>